//
//  PurchaseInformationViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/3.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "PurchaseInformationViewController.h"
#import "MyOfferInformationViewController.h"
#import "PurchaseInforViewModel.h"
#import "PurchaseInformationModel.h"

@interface PurchaseInformationViewController ()<PurchaseInformationDelegate>
{
    NSMutableDictionary * requestDic;
}
@property (nonatomic, strong) PurchaseInforViewModel *purchaseViewModel;

@property (nonatomic, strong) PurchaseInformationModel *model;

@end

@implementation PurchaseInformationViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"求购详情";
    
    self.purchaseViewModel = [[PurchaseInforViewModel alloc] initWithViewToViewModel:self.groupedTableView theSuperView:self.view];
    self.purchaseViewModel.delegate = self;
    self.purchaseViewModel.orderStr = self.orderStr;
    [self addNavigationItemWithImageNames:@[@"icon_fenxiang"] isLeft:NO target:self action:@selector(rightAction:) tags:@[@220]];
    requestDic = [@{
//                    @"id":koString(self.orderStr),
                    @"id":@"20",
                    @"pageSize":@10
                    } mutableCopy];
    [self headerRereshing];
}

- (void)rightAction:(UIButton *)sender
{
    // 分享
}

#pragma mark -- PurchaseInformationDelegate
- (void)purInformationDidSelectRowAtIndexPath:(NSIndexPath *)infor_row
{
    if (infor_row.section == 2) {
        MyOfferInformationViewController * offerInforVC = [MyOfferInformationViewController new];
        [self.navigationController pushViewController:offerInforVC animated:YES];
    }
}

- (void)setPur_type:(PurchaseType)pur_type
{
    _pur_type = pur_type;
}


#pragma mark -- 数据请求
- (void)headerRereshing
{
    self.page = 1;
    [self loadData];
}

- (void)footerRereshing
{
    if (self.page < self.model.data.total) {
        self.page ++;
        [self loadData];
    } else {
        [GLGWProgressHUD showNotice:@"没有更多服务的买家了！" view:nil];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }
}

- (void)loadData
{
    [requestDic setObject:@(self.page) forKey:@"page"];
    @weakify(self)
    [[self.purchaseViewModel.service_RecommendCommand execute:requestDic] subscribeNext:^(id  _Nullable x) {
        @strongify(self)
        self.model = (PurchaseInformationModel *)x;
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    } error:^(NSError * _Nullable error) {
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }];
}

@end
